package com.ysg.utils;


import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.ysg.constant.FileConstant;
import com.ysg.http.data.ApiService;
import com.ysg.http.data.entity.config.AppConfig;

public class YConfigUtil {

    /**
     * 实名认证开关
     */
    public static String getTicket(){
        String ticket = "";
        String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
        boolean whiteIp = YSPUtils.getInstance().isWhiteIp();
        if (YStringUtil.isNotEmpty(config) && !whiteIp){
            try {
                Log.e("config", ""+config);
                AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                String vipManage = configBean.getSwitchs().getVipManage();
                if (YChannelUtil.getInstance().xiaomi()){
                    vipManage = configBean.getXiaomi().getVipManage();
                }else if (YChannelUtil.getInstance().huawei()){
                    vipManage = configBean.getHuawei().getVipManage();
                }else if (YChannelUtil.getInstance().vivo()){
                    vipManage = configBean.getVivo().getVipManage();
                }else if (YChannelUtil.getInstance().oppo()){
                    vipManage = configBean.getOppo().getVipManage();
                }
                if (YStringUtil.eq(1, vipManage)){
                    ticket = "1";
                }else if (YStringUtil.eq(2, vipManage)){
                    if (YSPUtils.getInstance().getTicketFree()){
                        ticket = "21";
                    }else{
                        ticket = "2";
                    }
                }
                Log.e("门票开关", ""+vipManage);
            }catch (Exception e){
            }
        }
        return ticket;
    }


    /**
     * 实名认证开关
     */
    public static int getTicketTime(){
        int ticketTime = 3 * 60;
        String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
        if (YStringUtil.isNotEmpty(config)){
            try {
                AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                ticketTime = configBean.getSwitchs().getVipTime();
                if (YChannelUtil.getInstance().xiaomi()){
                    ticketTime = configBean.getXiaomi().getVipTime();
                }else if (YChannelUtil.getInstance().huawei()){
                    ticketTime = configBean.getHuawei().getVipTime();
                }else if (YChannelUtil.getInstance().vivo()){
                    ticketTime = configBean.getVivo().getVipTime();
                }else if (YChannelUtil.getInstance().oppo()){
                    ticketTime = configBean.getOppo().getVipTime();
                }
            }catch (Exception e){
                ticketTime = 3 * 60;
            }
        }
        return ticketTime;
    }

    /**
     * 实名认证开关
     */
    public static boolean isRealSwitch(){
        boolean open = false;
        String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
        if (YStringUtil.isNotEmpty(config)){
            try {
                AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                String vipSwitch = configBean.getSwitchs().getRealSwitch();
                if (YChannelUtil.getInstance().xiaomi()){
                    vipSwitch = configBean.getXiaomi().getRealSwitch();
                }else if (YChannelUtil.getInstance().huawei()){
                    vipSwitch = configBean.getHuawei().getRealSwitch();
                }else if (YChannelUtil.getInstance().vivo()){
                    vipSwitch = configBean.getVivo().getRealSwitch();
                }else if (YChannelUtil.getInstance().oppo()){
                    vipSwitch = configBean.getOppo().getRealSwitch();
                }
                if (YStringUtil.eq(1, vipSwitch)){
                    return true;
                }
            }catch (Exception e){
            }
        }
        return open;
    }

    /**
     * 支付宝
     */
    public static boolean isAlipaySwitch(){
        boolean open = true;
        String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
        if (YStringUtil.isNotEmpty(config)){
            try {
                AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                String vipSwitch = configBean.getSwitchs().getAlipaySwitch();
                if (YChannelUtil.getInstance().xiaomi()){
                    vipSwitch = configBean.getXiaomi().getAlipaySwitch();
                }else if (YChannelUtil.getInstance().huawei()){
                    vipSwitch = configBean.getHuawei().getAlipaySwitch();
                }else if (YChannelUtil.getInstance().vivo()){
                    vipSwitch = configBean.getVivo().getAlipaySwitch();
                }else if (YChannelUtil.getInstance().oppo()){
                    vipSwitch = configBean.getOppo().getAlipaySwitch();
                }
                if (YStringUtil.noEq(1, vipSwitch)){
                    return false;
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return open;
    }

    /**
     * 微信支付
     */
    public static boolean isWechatSwitch(){
        boolean open = true;
        String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
        if (YStringUtil.isNotEmpty(config)){
            try {
                AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                String vipSwitch = configBean.getSwitchs().getWechatPaySwitch();
                if (YChannelUtil.getInstance().xiaomi()){
                    vipSwitch = configBean.getXiaomi().getWechatPaySwitch();
                }else if (YChannelUtil.getInstance().huawei()){
                    vipSwitch = configBean.getHuawei().getWechatPaySwitch();
                }else if (YChannelUtil.getInstance().vivo()){
                    vipSwitch = configBean.getVivo().getWechatPaySwitch();
                }else if (YChannelUtil.getInstance().oppo()){
                    vipSwitch = configBean.getOppo().getWechatPaySwitch();
                }
                if (YStringUtil.noEq(1, vipSwitch)){
                    return false;
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return open;
    }

    /**
     * 首页的tab名称
     */
    public static String getMainTabName(){
        String name = "首页";
        String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
        if (YStringUtil.isNotEmpty(config)){
            try {
                AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                name = configBean.getSwitchs().getTabName();
                if (YChannelUtil.getInstance().xiaomi()){
                    name = configBean.getXiaomi().getTabName();
                }else if (YChannelUtil.getInstance().huawei()){
                    name = configBean.getHuawei().getTabName();
                }else if (YChannelUtil.getInstance().vivo()){
                    name = configBean.getVivo().getTabName();
                }else if (YChannelUtil.getInstance().oppo()){
                    name = configBean.getOppo().getTabName();
                }
            }catch (Exception e){
            }
        }
        return name;
    }

    /**
     *
     */
    public static String getBaseUrl(){
        String url = "";
        if (!ApiService.userLocalUrl){
            String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
            if (YStringUtil.isNotEmpty(config)){
                try {
                    AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                    url = configBean.getSwitch().getBaseUrl();
                    if (YChannelUtil.getInstance().xiaomi()){
                        url = configBean.getXiaomi().getBaseUrl();
                    }else if (YChannelUtil.getInstance().huawei()){
                        url = configBean.getHuawei().getBaseUrl();
                    }else if (YChannelUtil.getInstance().vivo()){
                        url = configBean.getVivo().getBaseUrl();
                    }else if (YChannelUtil.getInstance().oppo()){
                        url = configBean.getOppo().getBaseUrl();
                    }
                }catch (Exception e){
                }
            }
        }
        return url;
    }

    /**
     * 支付宝-原生
     */
    public static boolean getPayApp(){
        boolean flag = false;
        String config = YSPUtils.getInstance().getString(FileConstant.app_config_file);
        if (YStringUtil.isNotEmpty(config)){
            try {
                AppConfig configBean = JSON.parseObject(config, AppConfig.class);
                String payApp = configBean.getSwitch().getPayApp();
                if (YChannelUtil.getInstance().xiaomi()){
                    payApp = configBean.getXiaomi().getPayApp();
                }else if (YChannelUtil.getInstance().huawei()){
                    payApp = configBean.getHuawei().getPayApp();
                }else if (YChannelUtil.getInstance().vivo()){
                    payApp = configBean.getVivo().getPayApp();
                }else if (YChannelUtil.getInstance().oppo()){
                    payApp = configBean.getOppo().getPayApp();
                }
                if (YStringUtil.eq(1, payApp)){
                    flag = true;
                }
            }catch (Exception e){
            }
        }
        return flag;
    }

}
